/*
 * @Author: 肖思汗 
 * @Date: 2025-06-10 09:29:01 
 * @Last Modified by: 肖思汗
 * @Last Modified time: 2025-07-05 15:11:13
 */

import { makeAutoObservable } from "mobx";
import myCollectionApi from "./myCollectionApi";

// 我的收藏
class MyCollectionStore {
    constructor() {
        makeAutoObservable(this, {}, { deep: false });
    }

    page: number = 1;//当前页面
    pageSize: number = 10;//分页数
    total: number = 0;//总数
    collectionList: Array<any> = [];//数据列表
    hasMore: boolean = true;//是否有更多数据
    loading: boolean = false;
    //获取下一页的数据
    async getNextGoodsList(reset = false) {

        if (reset) {
            this.page = 1;

            this.hasMore = true;
        } else if (!this.hasMore || this.loading) {
            return;
        } else {
            this.page++;
        }
        this.loading = true;

        myCollectionApi.getlistMyCollect(this.page, this.pageSize).then(async res => {
            if (reset) {
                this.collectionList = [];
                await new Promise(resolve => setTimeout(resolve, 100));
                this.collectionList = [...res.rows];
            } else {
                this.collectionList = [...this.collectionList, ...res.rows];
            }
            this.total = res.total;
            this.hasMore = (res.rows.length === this.pageSize);
            await new Promise(resolve => setTimeout(resolve, 100));
            this.loading = false;
        });

    }


}

const myCollectionStore = new MyCollectionStore();

export default myCollectionStore;